C<template>
  <div class="container">

    <div class="box" v-for="item,index in this.dataList" :key="index">
      <el-card class="box-card " v-if="item.show">
        <div slot="header" class="clearfix">
          <span class="header-title">{{item.name}} </span>
          <span v-if="item.subTitle">{{item.subTitle}}</span>
        </div>
        <!-- 仓库管理 -->
        <div class="item label" v-if="index == 3">
          <store-manage-view :list="item.list"></store-manage-view>
        </div>
        <div class="item label" v-else-if="index == 5">
          <venue-goods-view :resData="item.list"></venue-goods-view>
        </div>
        <!-- 指派商品数 -->
        <div class="item label" v-else-if="index == 6">
          <div class="cell" v-for="val,key in item.list" :key="key">
            {{val.name}} : {{val.total}} (件)
          </div>
        </div>
        <!-- 场馆止售数 -->
        <div class="item label" v-else-if="index == 8">
          <div class="venueStop">
            <div class="venueStop-list">
              <span class="cell">当日场馆止售数</span>
              <div class="cell" v-for="v1,k1 in item.list.today" :key="k1">
                <span>{{v1.name}} : {{v1.total}} (件)</span>
              </div>
            </div>

            <div class="venueStop-list">
              <span class="cell">历史场馆止售数</span>
              <div class="cell" v-for="v2,k2 in item.list.history" :key="k2">
                <span> {{v2.name}} : {{v2.total}} (件)</span>
              </div>
            </div>
            <div class="venueStop-list">
              <span class="cell">今日回收商品</span>
              <div class="cell" v-for="v2,k2 in item.list.backGoodsToday" :key="k2">
                <span> {{v2.name}} : {{v2.count}} (件) {{v2.mCount}} (元)

                </span>
              </div>
            </div>

          </div>
        </div>



        <div class="item50" v-else-if="index == 2">

          <div class="cell1 label" v-for="val,i5 in item.list" :key="i5">
            <div>
              {{val.name}} : {{val.value}} {{val.unit}}
            </div>
          </div>
        </div>

        <div class="item label" v-else v-for="val,i in item.list" :key="i">
          <div class="cell">
            {{val.name}} : {{val.value}} {{val.unit}}
          </div>
        </div>
      </el-card>
    </div>

  </div>
</template>

<script>
import {
  userManager, businessManage, fundManager, incomeManager,
  allowance, stopShotArea, venueStopGoods, venueGoodsCount, storeManage, venueGiftCountInfo,
  venueTurnGoodsPrepare
} from "@/api/system/workbench";
import { compare } from './compute';
import storeManageView from './storeManageView.vue';
import venueGoodsView from './venueGoodsView'
import VenueGoodsView from "./venueGoodsView.vue";
import { checkPermi } from "@/utils/permission"; // 权限判断函数

export default {
  name: "Workbench",//工作台,
  components: {
    storeManageView,
    venueGoodsView,
    VenueGoodsView
  },
  data() {
    return {
      // 遮罩层
      loading: true,

      dataList: [
        //用户管理
        {
          name: '用户管理', subTitle: '',show : false, list: [
            { name: '总用户数', value: 0, unit: '个' },
            { name: '有效会员', value: 0, unit: '个' },
            { name: '金牌席位', value: 0, unit: '个' },
            { name: '银牌席位', value: 0, unit: '个' },
            { name: '游客', value: 0, unit: '个' },
          ]
        },

        {
          name: '平台代收费用管理', subTitle: '',
          show : false,
          list: [
            { name: '手续费收益总和', value: 0, unit: '元' },
            { name: '税费总和', value: 0, unit: '元' },
            //  { name: '佣金转余额手续费总和', value: 0, unit: '元' },
            { name: '手续费现金收益总和', value: 0, unit: '元' },
            { name: '手续费积分收益总和', value: 0, unit: '元' },
          ]
        },
        {
          name: '资金管理', subTitle: '',show : false,
          list: [
            { name: '系统总入金', value: 0, unit: '元' },
            { name: '佣金提取额', value: 0, unit: '元' },
            { name: '订单退款额', value: 0, unit: '元' },
            { name: '用户账户总余额', value: 0, unit: '元' },
            { name: '平台贡献值', value: 0, unit: '元' },
            { name: '用户账户金积分总余额', value: 0, unit: '个' },
            { name: '用户账户银积分总余额', value: 0, unit: '个' },
            { name: '用户账户佣金总余额', value: 0, unit: '元' },
            { name: '后台总添加现金', value: 0, unit: '元' },
            { name: '后台总添加金积分', value: 0, unit: '个' },
            { name: '后台总添加银积分', value: 0, unit: '个' },
            { name: '后台充值消费券总额', value: 0, unit: '' },
            { name: '金积分总产出', value: 0, unit: '个' },
            { name: '金积分总消费', value: 0, unit: '个' },
            { name: '银积分总产出', value: 0, unit: '个' },
            { name: '银积分总消费', value: 0, unit: '个' },
            { name: '消费券总产出', value: 0, unit: '' },
            { name: '消费券总消耗', value: 0, unit: '' },
            { name: '消费券总余额', value: 0, unit: '' },
          ]
        },
        {
          name: '仓库管理', subTitle: '',show : false, list: [
            { name: '消费品商品未提货数量', value: 0, unit: '个' },
            { name: '已提货数量', value: 0, unit: '个' },
            { name: '已发货数量', value: 0, unit: '个' },
          ]
        },
        {
          name: '交易管理', subTitle: '',show : false, list: [
            { name: '今日转卖订单总交易额', value: 0, unit: '元' },
            { name: '历史转卖订单总交易额', value: 0, unit: '元' },
            // { name: '金积分商品总交易额', value: 0, unit: '元' },
            { name: '消费品总交易额', value: 0, unit: '元' },
            { name: '当日弃单保证金总和', value: 0, unit: '元' },
            { name: '历史弃单保证金总和', value: 0, unit: '元' },
            { name: '昨日订单金额', value: 0, unit: '元' },
            { name: '今日订单金额', value: 0, unit: '元' },
            { name: '佣金消费总额', value: 0, unit: '元' },
            { name: '银积分消费总额', value: 0, unit: '元' },
          ]
        },

        { name: '场馆竞价品数量', subTitle: '',show : false, list: [

          ] },
        {
          name: '止售区商品数量', subTitle: '',show : false, list: {}
        },
        {
          name: '开馆之礼消费统计', subTitle: '', show : false,
          list: [
            { name: '银积分消费总和', value: 0, unit: '个' },
            { name: '现金消费总和', value: 0, unit: '元' }
          ]
        },
        { name: '场馆止售数', subTitle: '',show : false, list: {} },
        { name: '空', subTitle: '',show : false, list: {} },
        { name: '空', subTitle: '',show : false, list: {} },
      ],
      // 表单参数
      form: {},
      ABName: ''

    };
  },

  computed: {
  },

  created() {
    this.getList();
  },

  methods: {
    checkPermi,
    getList() {
      this.loading = true;
      //用户管理
      if (checkPermi(['workbench:user'])){
        this.dataList[0].show = true;
        userManager(this.queryParams).then((response) => {
          let data = response.data
          let list = this.dataList[0].list;
          list.forEach((item, index) => {
            switch (item.name) {
              case '总用户数': item.value = data.userTotal; break;
              case '金牌席位': item.value = data.glodVipTotal; break;
              case '银牌席位': item.value = data.sliverVipTotal; break;
              case '有效会员': item.value = data.effectVipUser; break;
              case '游客': item.value = data.ordinaryVipUser; break;
            }
          })
        });
      }

      //资金管理
      if (checkPermi(['workbench:capital'])){
        this.dataList[2].show = true;
        fundManager(this.queryParams).then((response) => {
          let data = response.data
          let list = this.dataList[2].list;
          list.forEach((item, index) => {
            switch (item.name) {
              case '用户账户总余额': item.value = data.cashTotal; break;
              case '系统总出金': item.value = data.totalOutMoney; break;
              case '对公账户余额': item.value = data.companiesAccount; break;
              case '订单退款额': item.value = data.orderRefundTotal; break;
              case '平台贡献值': item.value = data.companyProfit; break;
              case '后台总添加佣金': item.value = data.backgroundAddAmount != null ? data.backgroundAddAmount.brokerageAdd : '0'; break;
              case '后台总添加现金': item.value = data.backgroundAddAmount != null ? data.backgroundAddAmount.cashAdd : '0'; break;
              case '后台总添加金积分': item.value = data.backgroundAddAmount != null ? data.backgroundAddAmount.goldAdd : '0'; break;
              case '后台总添加银积分': item.value = data.backgroundAddAmount != null ? data.backgroundAddAmount.silverAdd : '0'; break;
              case '金积分总消费': item.value = data.outputConsumer != null ? data.outputConsumer.goldSubtract : '0'; break;
              case '银积分总消费': item.value = data.outputConsumer != null ? data.outputConsumer.silverSubtract : '0'; break;
              case '金积分总产出': item.value = data.outputConsumer != null ? data.outputConsumer.goldAdd : '0'; break;
              case '银积分总产出': item.value = data.outputConsumer != null ? data.outputConsumer.silverAdd : '0'; break;
              case '用户账户佣金总余额': item.value = data.brokerageAmountTotal; break;
              case '系统总入金': item.value = data.totalInMoney; break;
              case '用户账户金积分总余额': item.value = data.goldSliverTotal.goldAmount ? data.goldSliverTotal.goldAmount : 0; break;
              case '用户账户银积分总余额': item.value = data.goldSliverTotal != null ? data.goldSliverTotal.silverAmount : 0; break;
              case '消费券总产出': item.value = data.inTotal; break;
              case '消费券总消耗': item.value = data.outTotal; break;
              case '消费券总余额': item.value = data.consumeAmount; break;
              case '后台充值消费券总额': item.value = data.consumeAddAmount; break;
            }
          })
        })
      }


      //平台收益管理
      if (checkPermi(['workbench:profit'])){
        this.dataList[1].show = true;
        incomeManager(this.queryParams).then((response) => {
          let data = response.data
          let list = this.dataList[1].list;
          list.forEach((item, index) => {
            switch (item.name) {
              case '手续费收益总和': item.value = data.totalResellCharge; break;
              case '税费总和': item.value = data.totalEquity; break;
              // case '佣金转余额手续费总和': item.value = data.totalBrokerageCharge; break;
              case '手续费现金收益总和': item.value = data.cashAndIntegralcharge != null ? data.cashAndIntegralcharge.cash : 0; break;
              case '手续费积分收益总和': item.value = data.cashAndIntegralcharge != null ? data.cashAndIntegralcharge.integral : 0; break;
            }
          })
        });
      }


      //交易管理
      if (checkPermi(['workbench:transaction'])){
        this.dataList[4].show = true;
        businessManage(this.queryParams).then((response) => {
          let data = response.data
          let list = this.dataList[4].list;
          list.forEach((item, index) => {
            switch (item.name) {
              case '今日转卖订单总交易额': item.value = data.resellOrderCountToday != null ? data.resellOrderCountToday.totalTodayOrder : 0; break;
              case '历史转卖订单总交易额': item.value = data.resellOrderCountHistory != null ? data.resellOrderCountHistory.totalHisOrder : 0; break;
              // case '金积分商品总交易额': item.value = data.goldGoodsCount != null ? data.goldGoodsCount.totalWaterSum : 0; break;
              case '消费品总交易额': item.value = data.consumerTotalCount != null ? data.consumerTotalCount.totalConsumeFee : 0; break;
              // case '今日竞价品订单': item.value = data.orderInfoToday; break;
              // case '昨日竞价品订单': item.value = data.orderInfoYesterday; break;
              // case '今日消费品订单': item.value = data.orderConsumerToday; break;
              // case '昨日消费品订单': item.value = data.orderConsumerYesterday; break;
              // case '今日开馆之礼订单': item.value = data.orderGiftToday; break;
              // case '昨日开馆之礼订单': item.value = data.orderGiftYesterday; break;

              case '昨日订单金额': item.value =
                (parseFloat(data.orderInfoYesterday != null ? data.orderInfoYesterday.mCount : 0) +
                  parseFloat(data.orderConsumerYesterday != null ? data.orderConsumerYesterday.mCount : 0) +
                  parseFloat(data.orderGiftYesterday != null ? data.orderGiftYesterday.mCount : 0)).toFixed(2); break;
              case '今日订单金额': item.value =
                (parseFloat(data.orderInfoToday != null ? data.orderInfoToday.mCount : 0) +
                  parseFloat(data.orderConsumerToday != null ? data.orderConsumerToday.mCount : 0) +
                  parseFloat(data.orderGiftToday != null ? data.orderGiftToday.mCount : 0)).toFixed(2); break;
              case '历史弃单保证金总和': item.value = data.streamCashCountHistory != null ? data.streamCashCountHistory.totalHisFail : 0; break;
              case '当日弃单保证金总和': item.value = data.streamCashCountToday != null ? data.streamCashCountToday.totalTodayFail : 0; break;
              case '佣金消费总额': item.value = data.brokerageConsumeAmount != null ?  data.brokerageConsumeAmount : 0; break;
              case '银积分消费总额': item.value = data.silverConsumeAmount != null ? data.silverConsumeAmount  : 0; break;
            }
          })
        });
      }


      //仓库管理
      if (checkPermi(['workbench:warehouse'])){
        this.dataList[3].show = true;
        storeManage(this.queryParams).then((response) => {
          let data = response.data
          let list = this.dataList[3].list;
          list.forEach((item, index) => {
            switch (item.name) {
              case '消费品商品未提货数量': item.value = data.noSendCount; break;
              case '已提货数量': item.value = data.hasTakeCount; break;
              case '已发货数量': item.value = data.hasSendCount; break;
            }
          })
        });
      }


      // //场馆竞价品数量
      if (checkPermi(['workbench:lotsnum'])){
        this.dataList[5].show = true;
        venueGoodsCount(this.queryParams).then((response) => {
          let data = response.data
          let todaySell = data.todaySell;
          let stockNum = data.stockNum;
          let goodsTomorrow = data.goodsTomorrow;
          let goodsToday = data.goodsToday;
          let a = (data.nowDays) % 2
          // todaySell.sort(compare('id', true));
          // todaySell.push(todaySell.shift());
          // stockNum.sort(compare('id', true));
          // stockNum.push(stockNum.shift());
          // goodsTomorrow.sort(compare('id', true));
          // goodsTomorrow.push(goodsTomorrow.shift());
          // goodsToday.sort(compare('id', true));
          // goodsToday.push(goodsToday.shift());
          this.dataList[5].list = data;
          this.dataList[5].subTitle = (a == 1 ? 'B' : 'A');
        });
      }


      //止售区商品数量
      if (checkPermi(['workbench:stopnum'])){
        this.dataList[6].show = true;
        stopShotArea(this.queryParams).then((response) => {
          let data = response.data
          // data.sort(compare('id', true));
          // data.push(data.shift());
          this.dataList[6].list = data;
        });

      }


      //开馆之礼消费统计
      if (checkPermi(['workbench:openingceremony'])){
        this.dataList[7].show = true;
        venueGiftCountInfo(this.queryParams).then((response) => {
          let data = response.data
          let list = this.dataList[7].list;
          list.forEach((item, index) => {
            switch (item.name) {
              case '银积分消费总和': item.value = data.silver; break;
              case '现金消费总和': item.value = data.balance; break;
            }
          })
        });
      }


      //场馆止售数
      if (checkPermi(['workbench:venue:stop'])){
        this.dataList[8].show = true;
        venueStopGoods(this.queryParams).then((response) => {
          let data7 = response.data
          this.dataList[8].list = data7;
        });
      }

      // //转场商品数
      // if (checkPermi(['workbench:venue:turnGoodInfo'])){
      //   this.dataList[11].show = true;
      //   venueTurnGoodsPrepare(this.queryParams).then((response) => {
      //     let data11 = response.data
      //     this.dataList[11].list = data11;
      //   });
      //   console.log(this.dataList[11])
      // }

    },

    // 把某个元素移到最后
    addNew(arr) {
      let y = 0;//定义y用于控制循环结束
      for (let i = 0; y < arr.length; y++) {
        if (arr[i].name === "总计") {
          // 循环到是0的位置就删除该元素0并且在arr末尾push进这个元素0，由于splice删除了该位置元素，所以i不用+1，下次循环仍然检查i位置的元素
          arr.push(arr.splice(i, 1)[0])
        }
        // 循环到不是0的位置就继续往后循环
        else i++;
      }
      // 返回操作后的原数组
      return arr;
    },



  },
};
</script>
<style lang="scss" scoped>
.container {
  height: calc(100vh - 84px);
  overflow-y: scroll;
  display: flex;
  flex-wrap: wrap;
  padding: 20px 5px;
  justify-content: space-around;

  .box {
    margin-bottom: 20px;
    width: 21%;
    .box-card {
      height: 100%;
    }
    .clearfix {
      width: 100%;
      display: flex;
      justify-content: space-between;
    }
    .header-title {
      font-size: 16px;
      font-weight: bold;
    }
  }
  .box:nth-child(3n) {
    width: 50%;
  }

  .box:nth-child(3n + 2) {
    width: 27%;
  }

  .item {
    .venueStop {
      display: flex;
      justify-content: space-between;
      .venueStop-list {
        width: 49%;
      }
    }
  }

  .item50 {
    display: flex;
    flex-wrap: wrap;
    .cell1 {
      width: 33%;
    }
  }

  .label {
    line-height: 28px;
    font-size: 14px;
    font-weight: bold;
  }
}
</style>
